home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / swirl / swirl.doc < prev    next >
Encoding:
Text File  |  1994-08-02  |  3.7 KB  |  85 lines

  1.  
  2.                   
  3.  
  4.     Swirl is a program that repeatedly modifies images in a regular way,
  5.     and often generates interesting patterns.
  6.     
  7.     Try it out with the following calling sequences:
  8.     
  9.         swirl 1 8 8
  10.         swirl 0 3 3
  11.         swirl 7 8 8
  12.         swirl 1 1 5
  13.         swirl 5 1 3 0.5 2
  14.     
  15.     Be patient -- it takes a little while to start up;  once it starts
  16.     cycling, it works pretty well.
  17.     
  18.     The user interface is about as hostile as can be.  Here it is:
  19.     
  20.         type 'q' to quit.
  21.         type 's' to stop cycling
  22.         type 's' to start cycling again
  23.         type 'i' to save the window as the image file "out.rgb"
  24.         (the window title bar reminds you of the parameters you 
  25.      used, and displays the current generation number.)
  26.     
  27.     Note:  When you type 's' to stop it, swirl will continue to calculate
  28.     the next generation until it is done, and will then display it.  Thus,
  29.     the "stop" command will not have an instant effect.  Just to prove that
  30.     the interface is as hostile as possible, I've rigged it so that if you
  31.     type another 's' because you think the first one didn't "take", that
  32.     will re-start it.
  33.     
  34.     Swirl takes 3, 4, or 5 parameters.  The first three must be integers. 
  35.     
  36.     Parameter 1 defines the initial pattern.  It can be any number from -1
  37.     to 7.  Patterns 1-7 are built-in patterns, and pattern 0 is solid black,
  38.     except that a middle square of pixels is turned on each generation.  If
  39.     you specify -1 for a pattern, swirl will read the image file called
  40.     "in.rgb" in your current directory, and will use it as the initial
  41.     pattern.  There is no limit on the image size, but big images run pretty
  42.     slowly.
  43.     
  44.     Parameters 2 and 3 specify the dx and dy transformations to use on each
  45.     generation.  Currently, values between 1 and 20 are valid.  See below
  46.     for a description of what dx and dy mean.  The value 0 for dx or dy
  47.     means no operation so you can get pure x or y distortion.  "swirl n 0 0"
  48.     does nothing forever.
  49.     
  50.     Parameters 4 and 5 are two floating-point parameters that are used to
  51.     modify many of the dx and dy transformations.  Their results vary from
  52.     transformation to transformation, and by default, their values are
  53.     1.0.  It is often a good idea to use small integers for parameters 4
  54.     and 5.
  55.     
  56.     What it does:
  57.     
  58.     I was trying to find some simple algorithms that generate interesting
  59.     patterns that could possibly be used as textures for texture maps, etc. 
  60.     All of the patterns produced wrap from top to bottom, and left to right.
  61.     
  62.     Swirl works as follows:  For each pixel (i, j) I keep 5 values -- the R,
  63.     G, and B components, and two floats, dx(i, j) and dy(i, j).  Typically,
  64.     the floats are small (on the order of -15 to 15).  Generation n+1 is
  65.     calculated from generation n as follows:
  66.     
  67.         At the pixel (i, j), find dx = dx(i, j) and dy = dy(i, j).
  68.     
  69.         Find the color (in generation n) of pixel (i+dx, j+dy).  Since
  70.         dx and dy are, in general, floats, do the appropriate filtering.
  71.         (If you go off the image, just wrap to the opposite side.)
  72.     
  73.         Assign this new color to the pixel (i, j) in generation n+1.
  74.     
  75.     Basically, the dx and dy values form a 2-D vector field that indicate
  76.     the flow direction (actually the negative of that).  If the dx and dy
  77.     are sinusoidal, you'll get swirling.  You can also do shearing,
  78.     electric attractive and repulsive fields, etc.
  79.     
  80.     
  81.     Suggestions welcome; bugs to /dev/null.  The code may change, but I'll
  82.     add features using higher numbers for starting values and dx and dy
  83.     specifications.
  84.                                            -- Tom Davis (davis@sgi.com)
  85.